const {
	Controller
} = require('uni-cloud-router')
module.exports = class ChatController extends Controller {
	async add() {
		const db = uniCloud.database();
		// 获取 `project-activity` 集合的引用
		const collection = db.collection('project-chat');

		const {
			content,
			author
		} = this.ctx.data
		const data = await collection.add({
			content,
			author,
			data: Date.now()
		})
		return data
	}
	// 获取活动列表
	async list() {
		const db = uniCloud.database();
		// 获取 `project-activity` 集合的引用
		const collection = db.collection('project-chat');
		const data2 = await collection.get()
		return data2
	}
	// 删除消息
	async deleteMsg() {
		const db = uniCloud.database();
		const collection = db.collection('project-chat');
		const {
			user_id,
			msg_id
		} = this.ctx.data
		let result = await collection.where({
			_id: msg_id
		}).remove()
		return {
			result
		}
	}
	// 删除消息
	async deleteMsg() {
		const db = uniCloud.database();
		const collection = db.collection('project-chat');
		const { user_id, msg_id } = this.ctx.data
		let result = await collection.where({
			_id:msg_id
		}).remove()
		return {
			result
		}
	}
}
